package com.example.demo.mapper;

import com.example.demo.entity.Like;
import org.apache.ibatis.annotations.*;

@Mapper
public interface LikeMapper {
     // 点赞
    @Insert("INSERT INTO `like` (user_id, post_id) VALUES (#{userId}, #{postId})")
    void insertLike(Like like);

    // 取消点赞
    @Delete("DELETE FROM `like` WHERE user_id = #{userId} AND post_id = #{postId}")
    void deleteLike(@Param("userId") Long userId, @Param("postId") Long postId);

    // 检查用户是否已经点赞
    @Select("SELECT COUNT(*) FROM `like` WHERE user_id = #{userId} AND post_id = #{postId}")
    int checkLike(@Param("userId") Long userId, @Param("postId") Long postId);

    // 获取帖子的点赞数
    @Select("SELECT COUNT(*) FROM `like` WHERE post_id = #{postId}")
    int getLikeCountByPostId(@Param("postId") Long postId);
}
